<template>
    <el-tree-select v-model="modelValue" :data="shelfData" :render-after-expand="false" style="width: 180px"
        :default-expand-all="true" :check-strictly="strictly" />
</template>
<script lang="ts" setup>
const shelfData = ref<any>([]);

const modelValue = defineModel();

const strictly = defineModel("strictly", { default: false });

onMounted(() => {
    callApi()
})
const callApi = () => {


    shelfApi.shelfTree().then((res: any) => {

        res.forEach((item: any) => {
            item.label = item.name
            item.value = item.id
        })

        //把扁平化的数据转成树型结构
        let eatFoods = res.reduce((duzi: any, currentValue: any) => {

            currentValue.children = res.filter((item: any) => {
                if (item.parentId == currentValue.id) {
                    return item
                }
            })
            if (currentValue.parentId == 0) {

                duzi.push(currentValue)
            }
            return duzi;
        }, [])


        shelfData.value = [
            { value: 0, label: "请选择货架" }
        ].concat(eatFoods)



    })
}
</script>